package com.zhang.spark_1.spark_core.operator.transform

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * @title:
 * @author: zhang
 * @date: 2021/12/5 18:51 
 */
object Spark04_RDD_Operator_Transform_Test {

  def main(args: Array[String]): Unit = {
    //获取spark的连接
    val conf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("operator")
    val sc: SparkContext = new SparkContext(conf)
    //TODO flatMap 小功能：将List(List(1,2),3,List(4,5))进行扁平化操作

    val rdd: RDD[Any] = sc.makeRDD(List(List(1, 2), 6, List(3, 4)))

    val rddMap: RDD[Any] = rdd.flatMap {
      case list: List[_] => list
      case data => data :: Nil
    }

    rddMap.collect().foreach(println)
    sc.stop()
  }
}
